/////////////////////////////////////////////////////////////////////////
// File:        LicenseChecking.h
// Purpose:     Class which is used to check new versions of the app, 
//              pass servers and the url to test licenses
// Author:      Tukero
// Modified by: 
// Copyright:   (c) Tukero <tukero@gmail.com>
// Licence:     GNU/LGPL v3
/////////////////////////////////////////////////////////////////////////

#ifndef _TNOD_LICENSECHECKING_H_
#define _TNOD_LICENSECHECKING_H_

#include "EsetInfo.h"
#include "TNodBase.h"

class LicenseChecking : public wxThread
{
public:
    enum LicenseActions
    {
        CHECK_VALIDITY = 1,
        CHECK_EXPIRATIONDATE
    };

    int              m_key;             //the id for the thread
    License         *m_license;         //the license wich will be checked
    LinkListLicense *m_validLicenses;   //link list, this thread will append here the license (if it is valid). Optional, can be NULL
    LinkListLicense *m_checkedLicenses;
    TNodBase        *m_parent;          //the parent thread which will be used to remove the reference to this thread. Optional, can be NULL
    unsigned int     m_actions;          //can be: CHECK_VALIDITY to verify if the license is valid to download updates OR CHECK_EXPIRATIONDATE to check the expiration date in the license
    EsetInfo        *m_esetInfo;        //the nod32 settings, used when the thread checks the expiration date, if it is NULL the thread will use default settings

    bool             m_LicWithNoExpirationOnly;

    wxCommandEvent  *m_DownloadEvent;
    wxEvtHandler    *m_HandlerForEvent;

    //for general use
    LicenseChecking(int key, License *license2Check, LinkListLicense *validLicenses, TNodBase *parent/*, bool countInMainApp = true*/, EsetInfo *esetInfo = NULL, unsigned int actions = CHECK_VALIDITY, wxThreadKind kind = wxTHREAD_DETACHED);
    //used to check a single license
    LicenseChecking(License *license2Check, TNodBase *parent, wxThreadKind kind = wxTHREAD_JOINABLE);

    virtual void *Entry();
    virtual void Exit();
private:
    void SendExtraEvent(int ID, License * license);
    void Checked();
    void AppendLicense2List(License* license2Append, LinkListLicense *licensesList);

    //wxString GetValueTagFromXml(const wxString xml);

    //returns the xml used to request the expire date of a license
    wxString GetValidityXML();

    void CheckValidity();
    void CheckExpirationDate();
};
#endif